// pages/customer/customer-list/customer-list.js
var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    search: {
      search_value: '',
      contact_status: 1,
    },
    datalist: [],
    page: 1,
  },

  bindSearchInput(e){
    this.setData({
      ['search.search_value']: e.detail.value
    })
  },

  bindDoSearch() {
    this.loadCustomerList(true);
  },

  bindTypeSelect(e) {
    this.setData({
      ['search.contact_status']: e.currentTarget.dataset.idx
    })
    this.loadCustomerList(true);
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    wx.setNavigationBarTitle({
      title: '我的客户',
    });
    this.loadCustomerList();
  },

  loadCustomerList: function(reset) {
    wx.showLoading({
      title: '加载中...',
      mask: true
    })
    if(reset){
      this.setData({
        datalist: [],
        page: 1,
      })
    }
    var that = this;
    var data = {
      point_url: app.server.adminApi.getCustomerList,
      admin_id: app.globalData.userInfo.id,
      page: this.data.page,
      search_value: this.data.search.search_value,
      contact_status: this.data.search.contact_status
    };
    console.log(app.globalData.userInfo);
    app.server.getConnect(data).then(function(res) {
      console.log(res);
      var temp = that.data.datalist;
      temp.push.apply(temp, res.data);
      that.setData({
        datalist: temp
      })
      wx.hideLoading();
    }, function(res) {
      console.log(res);
      wx.hideLoading();
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    app.pageOnloadInit(this, app);
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    app.pageOnloadInit(this, app);
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    this.data.page = this.data.page + 1;
    this.loadCustomerList();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})
